//
//  DFProductModel.swift
//  DailyFresh
//
//  Created by Arthur on 2017/9/26.
//  Copyright © 2017年 DailyFresh. All rights reserved.
//
/*
"psc": "",
"gsp": "",
"ordering": 1000000090,
"gii": "daojishi",
"sell_out": false,
"nuo": 0,
"promotion_id": "",
"promote_tag": "https://j-image.missfresh.cn/img_20170605114049455.png",
"type": "product",
"dt": "",
"product_tags": [{
"color": 13027014,
"name": " 产地直采",
"icon": "https://image.missfresh.cn/category_tag_images/62DE96B73273E49C0BE0A2935452566B.PNG",
"type": "property"
}],
"price": 7581,
"product_tag": [{
"color": 13027014,
"name": " 产地直采",
"icon": "https://image.missfresh.cn/category_tag_images/62DE96B73273E49C0BE0A2935452566B.PNG",
"type": "property"
}],
"pgo": 100000,
"vip_product": 0,
"sku": "p-qsdzx",
"stock": 9,
"pao": 0,
"image": "https://image.missfresh.cn/5396d4d468de472f97de69f2d39c2834.jpg",
"enabled_banner": 1,
"cart_btn_name": "加入购物车",
"ipt": 0,
"buy_permission": 0,
"seckill_limit": 0,
"cart_btn_name_group": "",
"unit": "1盒",
"opt": "https://j-image.missfresh.cn/img_20170605114049455.png",
"vip_price_pro": {
    "price_up": {
        "show_type": 1,
        "color": 16761741,
        "price": 7581,
        "name": "可用券价"
    },
    "price_down": {
        "show_type": 1,
        "color": 16730257,
        "price": 3990,
        "name": "会员价"
    }
},
"subtitle": "从湖里到手里 还活蹦乱跳着",
"name": "清水大闸蟹 公2.0两,(2只)母1.5两, (2只)",
"cart_image": "https://j-image.missfresh.cn/img_20170425134548759.png",
"nationwide": 0,
"vip_price": 3990

*/
import UIKit
import SwiftyJSON

class DFProductModel: DFProductBaseModel {
    var promote_tag: String = "" // 优惠活动标签,图片链接
    var image: String = "" // 图片
    var name: String = ""
    var subtitle: String = ""
    var vip_price: Float = 0.0
    var price: Float = 0.0
    var product_tags: Array<DFProductTag> = []
    var priceUp: DFProductPrice?
    var priceDown: DFProductPrice?
    override init(json: JSON) {
        
        super.init(json: json)
        
        
        let tags = json["product_tags"].arrayValue
        product_tags = tags.map({ (json) -> DFProductTag in
            let tag = DFProductTag.init(json: json)
            return tag
        })
        
        let vip_price_pro = json["vip_price_pro"]
        priceUp = DFProductPrice.init(json: vip_price_pro["price_up"])
        priceDown = DFProductPrice.init(json: vip_price_pro["price_down"])
        
        promote_tag = json["promote_tag"].stringValue
        image = json["image"].stringValue
        name = json["name"].stringValue
        subtitle = json["subtitle"].stringValue
        vip_price = json["vip_price"].floatValue
        price = json["price"].floatValue

    }
}

// 标签
class DFProductTag: DFModel {
    var icon: String = "" // 图片
    var name: String = ""
    var type: String = ""
    
    override init(json: JSON) {
        super.init(json: json)
        name = json["name"].stringValue
        icon = json["icon"].stringValue
        type = json["type"].stringValue
        
    }
    
}

// 价格
class DFProductPrice: DFModel {
//    var color: Int = "" // 图片
    var name: String = ""
    var price: Int = 0
    
    override init(json: JSON) {
        super.init(json: json)
        name = json["name"].stringValue
        price = json["price"].intValue
        
    }
    
}
